package com.thread.threadfirst.javaBase.java8;

import net.bytebuddy.agent.builder.AgentBuilder;
import sun.awt.image.IntegerComponentRaster;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;

/**
 * removeIf
 */
public class MapTest {

    private static class Role{
        private Long Id;
        private String name;
        private Integer gold;

        public Role(Long id, String name, Integer gold) {
            Id = id;
            this.name = name;
            this.gold = gold;
        }

        public Long getId() {
            return Id;
        }

        public void setId(Long id) {
            Id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getGold() {
            return gold;
        }

        public void setGold(Integer gold) {
            this.gold = gold;
        }

        @Override
        public String toString() {
            return "Role{" +
                    "Id=" + Id +
                    ", name='" + name + '\'' +
                    ", gold=" + gold +
                    '}';
        }
    }

    public static void main(String[] args) {
        Map<Integer,Role> map=new HashMap();
        map.put(1,new Role(1L,"luffy",33));
        map.put(2,new Role(2L,"zoro",44));
        map.put(3,new Role(3L,"sanji",55));

        map.entrySet().removeIf(entry->entry.getKey()!=2);//remove移除key!=2的元素
        System.out.println(map);

        List<String> roleList=new ArrayList<>();
        roleList.add("33");
        roleList.add("22");
        roleList.add("11");

        Predicate<String> predicate= s->s.equals("22");//remove移除=22的元素
        roleList.removeIf(predicate);
        System.out.println(roleList);
    }
}
